package com.netsdk.web.callback;

import com.netsdk.lib.NetSDKLib;
import com.netsdk.lib.ToolKits;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import lombok.extern.slf4j.Slf4j;

import static com.netsdk.lib.NetSDKLib.EVENT_IVS_ACCESS_CTL;

/**
 * @Author aqie
 * @Date 2022/3/25 14:14
 * @desc
 */
@Slf4j
public class MessageCallBack implements NetSDKLib.fMessCallBack{
    private MessageCallBack() {
    }

    private static class CallBackHolder {
        private static final MessageCallBack cb = new MessageCallBack();
    }

    public static MessageCallBack getInstance() {
        return CallBackHolder.cb;
    }

    @Override
    public boolean invoke(int lCommand, NetSDKLib.LLong lLoginID, Pointer pStuEvent, int dwBufLen,
                          String strDeviceIP, NativeLong nDevicePort, Pointer dwUser) {
        switch (lCommand) {
            // 门禁事件
            case NetSDKLib.NET_ALARM_ACCESS_CTL_EVENT: {
                NetSDKLib.ALARM_ACCESS_CTL_EVENT_INFO msg = new NetSDKLib.ALARM_ACCESS_CTL_EVENT_INFO();
                ToolKits.GetPointerData(pStuEvent, msg);
                log.info("门禁事件 {}", msg);
                break;
            }
            case EVENT_IVS_ACCESS_CTL: {
                NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO msg = new NetSDKLib.DEV_EVENT_ACCESS_CTL_INFO();
                ToolKits.GetPointerData(pStuEvent, msg);
                log.info("门禁事件2 {}", msg);
                break;
            }

        }
        return true;
    }
}
